<#include '/admin/header.html' >
<#assign imageuploader="com.enation.framework.directive.ImageUploaderDirectiveModel"?new()>
<style>
.form-table th {
	width: 150px;
}
</style>

<script type="text/javascript">
	//上传图片插件配置
	var image_uploader_setting = {
		imageName : "payImg",	// 表单提交时 的name
		subFolder : "payment",		// 上传目录
		showImgs : [],	//显示的img值数组，不提交。只做显示用
		actualImgs : [],	// 实际的img值数组，会提交
		fileNumLimit:1 //最多上传图片个数
	}
</script>

<div class="main">
	<div class="shadowBoxWhite wf100 whiteBox">
		<form id="addpayCfgForm" method="post" class="validate">
			<table cellspacing="1" cellpadding="3" width="100%"
				class="form-table" id="pluginTable">
				<tr id="first">
					<th>支付方式：</th>
					<td><select name="type" id="pluginList" onchange="bian()">
							<option value="">请选择要添加的支付方式</option> 
							<#list pluginList as plugin>
							<option value="${plugin.id!'' }">${plugin.name!'' }</option> </#list>
					</select></td>
				</tr>
				<tr id="name">
					<th>支付方式名称：</th>
					<td><input type="text" class="easyui-validatebox input_text"
						name="name" id="payment_name" data-options="required:true" validType="string" maxlength="20"/></td>
				</tr>
				<tr id="online">
					<th>是否属于网上支付</th>
					<td>
						<input type="radio" value="1" name="isOnline" checked="checked" > 是&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="radio" value="0" name="isOnline" > 否&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<label style="color: red;">注：重要参数，认真选择。否则会造成支付出现错误！</label>
					</td>
				</tr>
				<tr id="img">
					<th>支付方式展示图片</th>
					<td>
						<@imageuploader />
					</td>
				</tr>
				<tr id="last">
					<th>介绍：</th>
					<td>
						<!-- <textarea name="biref" id="biref"></textarea> -->
						<script id="editor" name="biref" type="text/plain" style="height:200px;width: 99%;"></script>
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
			</table>
		</form>
		<div class="buttonWrap">
			<a href="javascript:void(0)" class="easyui-linkbutton" id="saveBtn" >保存</a>
		</div>
	</div>
</div>
<script type="text/javascript">

	var ue = UE.getEditor('editor',{
		zIndex:0,
	});

	$(function() {
		
		$("#saveBtn").click(function(){
			var savebtn = $(this);
			var formflag= $("#addpayCfgForm").form('validate');
			if(formflag) {
				//pluginList
				var type = $("#pluginList").val();
				if(type == "") {
					$.Loading.error("请选择支付方式！");	
					
					savebtn.linkbutton("enable");
					return;
				}
			}
			if(formflag){
				$.Loading.success("正在提交......");
				savebtn.linkbutton("disable");
			 	var options = {
					url : "${ctx}/shop/admin/payCfg/save-add.do",
					type : "POST",
					dataType : "json",
					success : function(result) {
						if(result.result==1){
							$.Loading.success(result.message); 
							parent.reloadTabGrid("支付方式");
							parent.CloseTabByTitle("添加支付方式");
						}else{
							$.Loading.error(result.message);
						}
						savebtn.linkbutton("enable");
						
				 	},
					 error : function(e) {
						$.Loading.error("出现错误 ，请重试");	
					}
			 	};
				$('#addpayCfgForm').ajaxSubmit(options);
			}else{
				$.Loading.hide();
				savebtn.linkbutton("enable");
			}
		})
	})
	
	function bian() {
		var pluginid = $("#pluginList").val();
		var name = $("#pluginList option:selected").text();
		loadHtml("", pluginid, name);
	}

	function loadHtml(paymentid, pluginid, name) {
		if (pluginid && pluginid != '') {
			$.ajax({
				url : "${ctx}/shop/admin/payCfg/get-plugin-html.do?ajax=yes&pluginId=" + pluginid
						+ "&paymentId=" + paymentid,
				success : function(html) {
					cleanTr();
					$("#pluginTable tr[id=name]").after(html);
					$("#payment_name").val(name);
				},
				error : function() {
					$.Loading.error("出错了");
				}
			});
		}
	}

	function cleanTr() {
		$("#pluginTable>tbody>tr").each(function() {
			if ($(this).attr("id") != "first"
					&& $(this).attr("id") != "last"
					&& $(this).attr("id") != "name"
					&& $(this).attr("id") != "img"
					&& $(this).attr("id") != "online"){
				$(this).remove();
			}
		});
	}
</script>

<#include '/admin/footer.html' >
